package run.siyuan.common.config;

import cn.hutool.core.util.StrUtil;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * @ClassName DruidConfig
 * @Description TODO
 * @Author siyuan
 * @Date 2023/4/13 16:52
 */
@Configuration
public class DruidConfig {

    @Value("${spring.datasource.database}")
    private String database;


    @Bean
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource druidDataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        String driverClassName = dataSource.getDriverClassName();
        driverClassName = StrUtil.format(driverClassName, dataSource);
        System.out.println("asdasdddddddddddddddf"+driverClassName);
        dataSource.setDriverClassName(driverClassName);
        return dataSource;
    }


}
